package cn.source.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.system.domain.TravelInfo;
import cn.source.system.service.ITravelInfoService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * 服务类目Controller
 *
 * @author sourcebyte.vip
 * @date 2024-06-19
 */
@RestController
@RequestMapping("/travel/info")
public class TravelInfoController extends BaseController
{
    @Autowired
    private ITravelInfoService travelInfoService;

    /**
     * 查询服务类目列表
     */
    @PreAuthorize("@ss.hasPermi('travel:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(TravelInfo travelInfo)
    {
        startPage();
        List<TravelInfo> list = travelInfoService.selectTravelInfoList(travelInfo);
        return getDataTable(list);
    }

    /**
     * 获取服务类目详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(travelInfoService.selectTravelInfoById(id));
    }

    /**
     * 新增服务类目
     */
    @PreAuthorize("@ss.hasPermi('travel:info:add')")
    @Log(title = "服务类目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TravelInfo travelInfo)
    {
        return toAjax(travelInfoService.insertTravelInfo(travelInfo));
    }

    /**
     * 修改服务类目
     */
    @PreAuthorize("@ss.hasPermi('travel:info:edit')")
    @Log(title = "服务类目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TravelInfo travelInfo)
    {
        return toAjax(travelInfoService.updateTravelInfo(travelInfo));
    }

    /**
     * 删除服务类目
     */
    @PreAuthorize("@ss.hasPermi('travel:info:remove')")
    @Log(title = "服务类目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(travelInfoService.deleteTravelInfoByIds(ids));
    }

    /**
     * 导出服务类目列表
     */
    @PreAuthorize("@ss.hasPermi('travel:info:export')")
    @Log(title = "服务类目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TravelInfo travelInfo)
    {
        List<TravelInfo> list = travelInfoService.selectTravelInfoList(travelInfo);
        ExcelUtil<TravelInfo> util = new ExcelUtil<TravelInfo>(TravelInfo.class);
        util.exportExcel(response, list, "服务类目数据");
    }
}
